æòÅⁿâoâiü[

Setting Breakpoints in JavaScript Code


    Adding the debugger statement to a script sets an unconditional breakpoint. For example, the following code causes the script to halt and display the script debug window as soon as it enters the setupBox function.

    function setupBox(box) {
       // break unconditionally at the next line
       debugger;
       box.width = 48;
       box.height = 48;
       box.url = "none";
    }

    To execute a breakpoint in runtime code, call the $.bp() method, as shown in the following example:

    function setupBox(box) {
       box.width = (box.width == undefined) ? $.bp() : 48;
       box.height = (box.height == undefined) ? $.bp() : 48;
       box.url = (box.url == undefined) ? $.bp() : "none";
    }

    This example breaks into the debugger if any of the width, height, or url attributes of the custom element are undefined. Of course, you wouldn't put bp method calls into production code -- it's more appropriate for shipping code to set default values for undefined properties, as the previous example does.